package com.study.shop.controller.product;

import com.study.shop.entity.common.R;
import com.study.shop.entity.dto.AttrDTO;
import com.study.shop.entity.dto.AttrValueDTO;
import com.study.shop.service.AttrService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
@RequiredArgsConstructor
public class AttrController {
    private final AttrService attrService;

    @GetMapping("/getAttr/{thirdLevel}")
    public R<List<AttrValueDTO>> getAttrByCategory(@PathVariable("thirdLevel") int thirdLevel) {
        List<AttrValueDTO> list = attrService.getAttrByCategory(thirdLevel);
        return R.success(list);
    }

    @PostMapping("/saveAttrInfo")
    public R<String> saveAttrInfo(@RequestBody AttrDTO attrDTO) {
        boolean success = attrService.saveAttrInfo(attrDTO);
        return R.success("保存成功");
    }

    @PutMapping("/updateAttrInfo")
    public R<String> updateAttrInfo(@RequestBody AttrDTO attrDTO) {
        boolean success = attrService.updateAttrInfo(attrDTO);
        return R.success("更新成功");
    }

    @DeleteMapping("/deleteAttrInfo/{id}")
    public R<String> deleteAttrInfo(@PathVariable("id") Integer id) {
        boolean success = attrService.deleteAttrInfo(id);
        return R.success("删除成功");
    }
}
